package com.demo.utils.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author ausu
 * @version 1.0
 * @description: TODO
 * @date 2023/2/27 14:36
 */
public class FutureTaskT{
    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<Integer>(
                () -> {
                    return 5;
                }
        );

        Thread thread = new Thread(futureTask,"Callable 任务执行线程");
        thread.start();

        try {
            Integer integer = futureTask.get();
            System.out.println("call() result: " + integer);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
